################################################################################
# Created By:Pietryka
# Creation Date:  2016-08-22
# Purpose: Plot the CCES coefs
# Questions: mpietryka@fsu.edu
################################################################################


# PREAMBLE =============================================


# LOAD PACKAGES -----------------
library(tidyverse)


# LOAD DATA -----------------

# Workspace from 'CCES3-Analysis-Fixed-Effects.R'
load("Data/CCES3-Analysis-Fixed-Effects.Rdata")



# CREATE PLOT  =============================================


dot_plot <- ggplot(cces_results, aes(x = forcats::fct_rev(equation),
                             y = beta,
                             fill = dot_type,
                             color = forcats::fct_rev(equation),
                             label = lab)) +
  geom_hline(yintercept = 0, linetype = 2, linewidth = 1) +
  geom_pointrange(aes(ymin = lb, ymax = ub),
                  shape = 21,
                  fatten = 8, linewidth = 2) +
  theme_minimal(base_size = 12) +
  expand_limits(y = -1.8) +
  geom_text(fontface = "bold",
            vjust = 1.7,
            size = 3) +
  coord_flip() +
  xlab(NULL) +
  ylab("Estimate (log odds)") +
  expand_limits(y = c(-1.8, 1.8)) +
  facet_wrap(~ y_lab, ncol = 2, as.table = TRUE, scales = "free_y") +
  theme(plot.subtitle = element_text(colour = "gray50")) +
  theme(plot.caption = element_text(colour = "gray50")) +
  theme(legend.position = "none") +
  theme(axis.text.y = element_blank()) +
  theme(text = element_text(size = 16)) +
  scale_fill_manual(values = c("white", "black")) +
  scale_color_grey(start = 0.2, end = 0.6)



graphics.off()
windows(5, 6)
dot_plot

# SAVE ===============================================


ggsave("Figures/CCES-Fixed-Effects.tiff", compression = "lzw")

